/**
 * @param {string} s
 * @param {number} k
 * @return {string}
 */
var reverseStr = function(s, k) {
    let res = ''
    let len = s.length
    for (let i = 0; i < len; i += 2*k) {
        if (len - i < k) {
            res += reverse(s.slice(i))
            break;
        }
        if (len -i < 2*k && len -i >=k ) {
            res += reverse(s.slice(i,i + k)) +  s.slice(i + k)
            break
        }
        res += reverse(s.slice(i, i+k)) + s.slice(i+k,i+ 2*k)   
    }


    function reverse(str) {
        let temp = ''
        for (let i = str.length-1; i >=0; i--) {
            temp += str[i]
        }
        return temp
    }
    return res
};
let s = "abcdefg"
let k = 2
console.log(reverseStr(s, k))